function LoginAssistant() {
	/** this is the creator function for your scene assistant object. It will be passed all the 
	*   additional parameters (after the scene name) that were passed to pushScene. The reference
	*   to the scene controller (this.controller) has not be established yet, so any initialization
	*   that needs the scene controller should be done in the setup function below.
	*/
}

/** this function is for setup tasks that have to happen when the scene is first created 
*/
LoginAssistant.prototype.setup = function() {		
	/** use Mojo.View.render to render view templates and add them to the scene, if needed.
	 * 
	 */
	
	/** setup widgets here-
	 * Instantiates UI widgets for login scene. Each widget requires attributes and a model.
	 * These are passed to the widget in a JSON object.
	 */
	this.controller.setupWidget("username",
          this.usernameAttributes = {
              hintText: $L('Type your username...'),
              autoFocus: true,
			  preventResize: true,
			  focusMode: Mojo.Widget.focusSelectMode,
			  autoReplace: false,
			  maxLength: 25,
			  textCase: Mojo.Widget.steModeLowerCase
          },
          this.usernameModel = {
              value: "",
              disabled: false
     });
	 
	 this.controller.setupWidget("password",
          this.passwordAttributes = {
              hintText: $L('Type your password...'),
			  preventResize: true,
			  focusMode: Mojo.Widget.focusSelectMode,
			  maxLength: 100,
          },
          this.passwordModel = {
              value: ""
     });
	 
	 this.controller.setupWidget("remembermeCheckbox",
          this.remembermeAttributes = {
              inputName: "remembermeCheckbox",
          },
          this.remembermeModel = {
              value: false,
              disabled: false
          });
	 
	 this.controller.setupWidget("loginButton",
         this.loginButtonAttributes = {
		 	type: Mojo.Widget.activityButton
             },
         this.loginButtonModel = {
             label : "Login",
             disabled: false
         });
		 
	this.controller.setupWidget("registerButton",
         this.registerButtonAttributes = {
		 	type: Mojo.Widget.Button
             },
         this.registerButtonModel = {
             label : "Register",
             disabled: false
         });
	 
	
	/** add event handlers to listen to events from widgets
	 */
	this.loginButtonHandler = this.loginButton.bindAsEventListener(this);
	this.registerButtonHandler = this.registerButton.bindAsEventListener(this);
}

/**This function recieves a JSON params that holds user data.  It updates the username
 *and password, then waits to recieve an action from user (Button press).
 *@param params JSON parameter that in this case holds user data.
 *
 */
LoginAssistant.prototype.activate = function(params) {
	 /** put in event handlers here that should only be in effect when this scene is active. For
	 * example, key handlers that are observing the document
	 * When the scene is activated, update the username and password text fields, and start the
	 * event listeners for taps on the 'login' and 'register' button.
	 */
	  if (params) {
	  	this.usernameModel.value = params.username;
	  	this.passwordModel.value = params.password;
		this.controller.modelChanged(this.usernameModel);
		this.controller.modelChanged(this.passwordModel);
	  }
	  
	  Mojo.Event.listen(this.controller.get('loginButton'),Mojo.Event.tap,this.loginButtonHandler);
	  Mojo.Event.listen(this.controller.get('registerButton'),Mojo.Event.tap,this.registerButtonHandler);
}

/** remove any event handlers you added in activate and do any other cleanup that should happen before
	  * this scene is popped or another scene is pushed on top
	  */
LoginAssistant.prototype.deactivate = function(event) {
	
	  Mojo.Event.stopListening(this.controller.get('loginButton'),Mojo.Event.tap,this.loginButtonHandler);
	  Mojo.Event.stopListening(this.controller.get('registerButton'),Mojo.Event.tap,this.registerButtonHandler);
}
/** this function should do any cleanup needed before the scene is destroyed as
	 *  a result of being popped off the scene stack
	 */
LoginAssistant.prototype.cleanup = function(event) {
	
}

/** This function is called when the login button is pressed. It will connect to the mySQL
 * database on the BMC Studios LLC. server and authenticate the user login. 
 */
LoginAssistant.prototype.loginButton = function(event) {
	if(!event)
		return;
	var userInfo = {
		'username': this.usernameModel.value,
		'password': this.passwordModel.value
	};
	this.authUser(userInfo);
}

/** This function is called when the register button is pressed. It pushes
 * the 'register' scene onto the scene stack and passes it the username/password
 * from the login textboxes.
 */
LoginAssistant.prototype.registerButton = function(event) {
	if(!event)
		return;
	var userInfo = {
		'username': this.usernameModel.value,
		'password': this.passwordModel.value
	};
	this.controller.stageController.pushScene('register', userInfo);
}

/** This function recieves a JSON UI, which holds the user data, and pushes it to
 * an authentication php and sends it's data to it's callback function.
 * @param UI JSON that holds user info.
 */
LoginAssistant.prototype.authUser = function(UI) {    
    var url = "http://www.bmcstudiosllc.com/starmap/" + "mobile_auth.php";

    try{
        var request = new Ajax.Request(url,
        {
            method:'get',
            parameters: {'username': UI.username, 'password': UI.password},
            evalJSON:'true',
            onComplete: this.authUserCallback.bind(this),
        });
    }
    catch (e)
    {
        Mojo.log.error(e);
        return 0;
    }
}

/** User authentication callback function that either returns an error (if login
 * isn't authentic or otherwise) and pushes the user info to the main screen.
 * @param ajaxResponse Response from server.
 */
LoginAssistant.prototype.authUserCallback = function(ajaxResponse) {
	this.controller.get('loginButton').mojo.deactivate();
	if (ajaxResponse.responseJSON.returnCode != 1) {
		Mojo.Controller.errorDialog(ajaxResponse.responseJSON.message);
	} else {
		var userInfo = {
		'username': this.usernameModel.value,
		'password': this.passwordModel.value
		};
		this.controller.stageController.pushScene('main', userInfo);
	}
}